<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	<link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	<link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	<link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
	<script src="Public/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="Public/uploadify/jquery.uploadify.min.js" type="text/javascript" charset="utf-8"></script>
	<link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css"/>
	<script type="text/javascript" charset="utf-8" src="Public/Admin/js/goods.js"></script>
	<!--百度编辑器-->
	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
   	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    
	<script>
		$(function(){
//		 alert(2);
         $('select[name=cid]').change(function(){
//       	alert(1);
            var tid=$('option::selected').attr('tid');
//          hidden=$("#hidden").val();
			$('input[name=tid]').attr('value',tid);
//           hidden=tid;
            if(tid==0){
            	alert('选择的是顶级分类不能添加商品');
            }

            $.ajax({
            	type:"post",
            	url:"{{U('getTypeAttr')}}",
            	data:{tid:tid},
            	dataType:'json',
            	success:function(phpData){
//          		alert(phpData);
//                定义空变量
          		var attr='';
				var spec='';
				$.each(phpData, function(k,v){
//					alert(v.taname);
//					alert(v.class);
         			if(v.class==0){
//								判定如果是属性的类型属性数据，就组合后写入属性的盒子中
						attr+='<tr class="info"><td>'+v.taname+'</td>';
						attr+='<td><select name="attr['+v.taid+']" id="">';
						attr+='<option value="">请选择</option>';
						$.each(v.tavalue, function(kk,vv) {
							attr+='<option value="'+vv+'">'+vv+'</option>';
						});
							attr+='</select></td></tr>';
					}else{
//							如果是规格写入规格盒子中
						spec+='<tr class="info"><td>'+v.taname+'</td>';	
						spec+='<td><select name="spec['+v.taid+'][gtvalue][]" id="">';
						spec+='<option value="">请选择</option>';
						$.each(v.tavalue, function(kk,vv) {
						spec+='<option value="'+vv+'">'+vv+'</option>';
							});
						spec+='</select></td><td>附加价格：';
						spec+='<input type="text" name="spec['+v.taid+'][added][]" id="" />';
						spec+='</td><td><span class="btn btn-success add-spec">增加规格</span>';
							spec+='</td></tr>';
					}
	      
				});
				$('#attr').html(attr);
			    $('#spec').html(spec);
            	}
            });
         })
		})
	</script>

</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post'>
		<fieldset>
			<legend>添加商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
						
							<select name="cid">
								<option value="0">-请选择-</option>
								{{foreach from="$cateData" key="$k" value="$v"}}
								<option value="{{$v['cid']}}" tid="{{$v['tid']}}">{{$v['_name']}}</option>
								{{endforeach}}
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="bid">
								<option value="0">-请选择-</option>
                                   {{foreach from="$brandData" key="$k" value="$v"}}
									<option value="{{$v['bid']}}">{{$v['bname']}}</option>
                                  {{endforeach}}
								
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname'/>
						</td>
					</tr>
					<tr class="info">
						<td>商品数量</td>
						<td>
							<input type="text" name='gnumber'/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value='件'/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='marketprice'/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice'/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click'/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				<tr class="info">
						<td>袖长</td>
						<td>
							<select name="" id="">
								<option value="">无袖</option>
								<option value="">无袖</option>
								<option value="">无袖</option>
							</select>
						</td>
				</tr>
				<tr class="info">
						<td>袖长</td>
						<td>
							<select name="" id="">
								<option value="">无袖</option>
								<option value="">无袖</option>
								<option value="">无袖</option>
							</select>
						</td>
				</tr>
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				<tr class="info">
					<td>尺寸</td>
						<td>
							<select name="" id="">
								<option value="">XL</option>
								<option value="">M</option>
								<option value="">S</option>
							</select>
						</td>
						<td>附加价格：
							<input type="text" name="" id="" />
						</td>
						<td>
							<span class="btn btn-success add-spec">增加规格</span>
						</td>
				</tr>
				<tr class="info">
					<td>尺寸</td>
						<td>
							<select name="" id="">
								<option value="">XL</option>
								<option value="">M</option>
								<option value="">S</option>
							</select>
						</td>
						<td>附加价格：
							<input type="text" name="" id="" />
						</td>
						<td>
							<span class="btn btn-success add-spec">增加规格</span>
						</td>
				</tr>	

			</table>
			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input class="file" type="file" name='pic' id='pic'/>
					</td>
					<td id='pic-list'>
					<div id="uploadList_pic">
	                  <ul>
	
	                   </ul>
	                </div>
					</td>
				</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input  type="file" name='photo' id='photo' />
					</td>
					<td id='photo-list'>
					<div id="uploadList">
	                  <ul>
	
	                   </ul>
	                </div>
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr class="info">
					<td>
						<!--<textarea name="intro" id="intro"></textarea>-->
			<script id="editor" name="intro" type="text/plain" style="width:1000px;height:200px;"></script>
			<script type="text/javascript">
				var ue = UE.getEditor('editor');
			</script>
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr class="info">
					<td>
						<!--<textarea name="service" id="service"></textarea>-->
			<script id="service" name="service" type="text/plain" style="width:1000px;height:200px;"></script>
			<script type="text/javascript">
				var ue = UE.getEditor('service');
			</script>
					</td>
				</tr>
			</table>
			<input type="hidden"name="tid" id="hidden" value="" />
			<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>

    <script type="text/javascript">
        $(function() {
            $('#pic').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
                'uploader' : '{{U('upload')}}',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 22,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:200px;' /><input type='hidden' name='pic' value='"+data.path+"'/></li>";
                    $("#uploadList_pic ul").prepend(li);
                }
            });
        });
    </script>
        <script type="text/javascript">
        $(function() {
            $('#photo').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
                'uploader' : '{{U('upload')}}',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 22,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:200px;' /><input type='hidden' name='big[]' value='"+data.path+"'/></li>";
                    $("#uploadList ul").prepend(li);
                }
            });
        });
    </script>

    <!--<li class="hide"><input type="" name="" id="" value="" /></li>-->
</body>
</html>